package com.qf.coupon.rule.impl;

import com.qf.coupon.rule.IRule;

import java.math.BigDecimal;

public class DijianRule implements IRule {

    //每满多少 - 1000
    private double must;
    //递减多少 - 100
    private double dijian;
    //最高只能减多少 - 500
    private double maxjian;


    @Override
    public boolean canUser(double money) {
        return money >= must;
    }

    @Override
    public double youhui(double money) {
        //计算需要减多少次
        int num = (int) (money / must);
        //计算优惠的额度
        double youhuiMoney = BigDecimal.valueOf(num).multiply(BigDecimal.valueOf(dijian)).doubleValue();
        //优惠的额度
        youhuiMoney = Math.min(youhuiMoney, maxjian);
        //返回优惠后的金额
        return BigDecimal.valueOf(money).subtract(BigDecimal.valueOf(youhuiMoney)).doubleValue();
    }
}
